﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TagPropagator.Data;

namespace TagPropagator
{
    public class RandomAgent : IPropagationAgent
    {
        public void Propagate(Graph graph, int iterations)
        {
            Random r = new Random();
            for (int i = 0; i < iterations; i++)
            {
                Console.WriteLine("iteracja {0}", i);
                int nodeId = r.Next(graph.Nodes.Count);
                Node n = graph.Nodes[nodeId];
                foreach (var neighbour in n.Neighbours.Keys)
                {
                    foreach (var tag in n.Tags.Keys)
                    {
                        double propagationValue = Math.Log10(n.Tags[tag] + 1) * n.Neighbours[neighbour] * Constants.N;
                        if (!graph.Nodes[neighbour].Tags.ContainsKey(tag))
                            graph.Nodes[neighbour].Tags.Add(tag, propagationValue);
                        else
                        {
                            double tagWeight = graph.Nodes[neighbour].Tags[tag];
                            if (tagWeight + propagationValue > n.Tags[tag] * n.Neighbours[neighbour]) continue;
                            else graph.Nodes[neighbour].Tags[tag] += propagationValue;
                        }
                    }
                }
            }
            

        }
    }
}
